package fina2.dcs.mail;

import java.util.Date;
import java.util.List;

import javax.mail.MessagingException;

import fina2.dcs.mail.manager.AttachInfo;
import fina2.dcs.mail.manager.MailPropsKey;
import fina2.dcs.mail.manager.MailUser;
import fina2.dcs.mail.owa.MailReaderImplOWA;

@SuppressWarnings("serial")
public class MailReader implements MailReaderBase {

	private MailReaderBase mailReaderImpl;

	public MailReader(MailUser mailUser) {
		switch (mailUser.getConnectionType()) {
		case MailPropsKey.MAIL_POP3_SMTP: {
			mailReaderImpl = new MailReaderPOP3(mailUser);
			break;
		}
		case MailPropsKey.MAIL_IMAP_SMTP: {
			mailReaderImpl = new MailReaderIMAP(mailUser);
			break;
		}
		case MailPropsKey.MAIL_OWA: {
			mailReaderImpl = new MailReaderImplOWA(mailUser);
			break;
		}
		case MailPropsKey.MAIL_EWS: {
			mailReaderImpl = new MailReaderPOP3(mailUser);
			break;
		}
		default: {
			throw new RuntimeException("Connection Not Supported!");
		}
		}
	}

	@Override
	public List<AttachInfo> getNewAttahcments(Date date) throws MessagingException {
		return mailReaderImpl.getNewAttahcments(date);
	}

	@Override
	public MailUser getMailUser() {
		return mailReaderImpl.getMailUser();
	}

}
